<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>
<body>
    <button>存</button>
    <button>取</button>
</body>
</html>
<script>
      function $(seletor) {
        return document.querySelectorAll(seletor);
    }
    
    let date = new Date();
    date.setDate(date.getDate()+7)
    $("button")[0].onclick = function () {
        document.cookie = 'username=zhamgsan;expires='+date;
        setTimeout(function(){
             location.href='./后台.html'
        },1000)
    }
    $("button")[1].onclick = function () {
        console.log(document.cookie)
    }
</script>